import sqlite3

cursor = None

def initDB(database_schema_string):
    global cursor
    # 创建数据库连接
    conn = sqlite3.connect(':memory:')
    cursor = conn.cursor()

    # 创建orders表
    cursor.execute(database_schema_string)

    # 插入5条明确的模拟记录
    mock_data = [
        (1, 1001, 'TSHIRT_1', 50.00, 0, '2023-10-12 10:00:00', None),
        (2, 1001, 'TSHIRT_2', 75.50, 1, '2023-10-16 11:00:00', '2023-08-16 12:00:00'),
        (3, 1002, 'SHOES_X2', 25.25, 2, '2023-10-17 12:30:00', '2023-08-17 13:00:00'),
        (4, 1003, 'HAT_Z112', 60.75, 1, '2023-10-20 14:00:00', '2023-08-20 15:00:00'),
        (5, 1002, 'WATCH_X001', 90.00, 0, '2023-10-28 16:00:00', None),
        (6, 1002, 'TSHIRT_2', 75.50, 1, '2023-11-16 11:00:00', '2023-11-16 12:00:00'),
        (7, 1003, 'SHOES_X2', 25.25, 1, '2023-12-17 12:30:00', '2023-12-17 13:00:00'),
        (8, 1001, 'HAT_Z112', 60.75, 1, '2023-11-20 14:00:00', '2023-11-20 15:00:00'),
        (9, 1002, 'WATCH_X001', 90, 1, '2023-09-16 11:00:00', '2023-09-16 12:00:00'),
        (10, 1003, 'SHOES_X2', 25.25, 1, '2023-09-17 12:30:00', '2023-09-17 13:00:00'),
        (11, 1001, 'HAT_Z112', 60.75, 1, '2023-09-20 14:00:00', '2023-09-20 15:00:00'),
        (12, 1001, 'TSHIRT_2', 75.50, 1, '2023-10-16 11:00:00', '2023-10-16 12:00:00'),
        (13, 1003, 'TSHIRT_2', 75.50, 1, '2023-09-16 11:00:00', '2023-09-16 12:00:00')
    ]

    for record in mock_data:
        cursor.execute(f'''
            INSERT INTO orders (id, customer_id, product_id, price, status, create_time, pay_time)
            VALUES (?, ?, ?, ?, ?, ?, ?)
            ''', record)

    # 提交事务
    conn.commit()

def ask_database(query):
    global cursor
    cursor.execute(query)
    records = cursor.fetchall()
    return records